package cn.cqie.attendance.teacher.controller;

import cn.cqie.attendance.common.util.Page;
import cn.cqie.attendance.common.util.PageBean;
import cn.cqie.attendance.teacher.pojo.*;
import cn.cqie.attendance.teacher.service.TeacherHomeworkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author wqh
 * @date 2021/7/6 12:59
 */
@RestController
@Api(tags = "教师端-教师作业模块")
@RequestMapping("/teacher/homework")
public class TeacherHomeworkController {

    @Autowired
    private TeacherHomeworkService teacherHomeworkService;

    @GetMapping("/queryHomeworkInfoByTeacherId")
    @ApiOperation("教师查看课程下的所有作业")
    public PageBean<TeacherHomeworkRes> queryHomeworkInfoByTeacherId(TeacherHomeworkReq param) {
        return teacherHomeworkService.queryHomeworkInfoByTeacherId(param);
    }

    @GetMapping("/queryCourseByTeacherId")
    @ApiOperation("查看当前教师的所有课程列表(新增作业里面的下拉框)")
    public Page<CourseListRes> queryCourseByTeacherId() {
        return teacherHomeworkService.queryCourseByTeacherId();
    }

    @GetMapping("/queryGroupsByCourseId")
    @ApiOperation("教师查看课程下的小组列表(新增作业里面的下拉框)")
    public Page<GroupListRes> queryGroupsByCourseId(@RequestParam(value = "courseId")Integer courseId) {
        return teacherHomeworkService.queryGroupsByCourseId(courseId);
    }


    @GetMapping("/queryStudentsByGroupId")
    @ApiOperation("教师查看课程下的小组中的学生列表(新增作业里面的下拉框)")
    public Page<StudentListRes> queryStudentsByGroupId(@RequestParam(value = "groupIds")String[] groupIds) {
        return teacherHomeworkService.queryStudentsByGroupId(groupIds);
    }

    @PostMapping("/insertHomeworkInfo")
    @ApiOperation("新增作业")
    public Page insertHomeworkInfo(InsertHomeworkReq param) throws ParseException {
        return teacherHomeworkService.insertHomeworkInfo(param);
    }

    /*@PostMapping("/insertHomeworkByStudentId")
    @ApiOperation("分配作业给具体的学生")
    public Page insertHomeworkByStudentId(@RequestParam(value = "groupId")String groupId,@RequestParam(value = "stuId")String stuId,@RequestParam(value = "publishHomeworkId") Integer publishHomeworkId) {
        return teacherHomeworkService.insertHomeworkByStudentId(groupId,stuId,publishHomeworkId);
    }*/

    /*@PostMapping("/insertHomeworkAttachment")
    @ApiOperation("新增作业添加一条附件记录")
    public Page insertHomeworkAttachment(@RequestParam(value = "address")String address,@RequestParam(value = "type") Integer type,@RequestParam(value = "publishHomeworkId") Integer publishHomeworkId) {
        return teacherHomeworkService.insertHomeworkAttachment(address,type,publishHomeworkId);
    }*/

    @PostMapping("/deleteHomeworkById")
    @ApiOperation("删除一条作业(教师发布的作业)")
    public Page deleteHomeworkById(@RequestParam(value = "id")Integer id) {
        return teacherHomeworkService.deleteHomeworkById(id);
    }

    @GetMapping("/queryHomeworkReplyByStatus")
    @ApiOperation("根据批复状态查询作业信息")
    public PageBean queryHomeworkReplyByStatus(ReplyHomeworkReq param) {
        return teacherHomeworkService.queryHomeworkReplyByStatus(param);
    }

    @PostMapping("/updateHomeworkById")
    @ApiOperation("根据作业id批复作业")
    public Page updateHomeworkById(@RequestParam(value = "score")float score,@RequestParam(value = "replyContent")String replyContent, @RequestParam(value = "id")Integer homeworkId,String address) {
       return teacherHomeworkService.updateHomeworkById(score,replyContent,homeworkId,address);
    }

    @GetMapping("/queryHomeworkAnswerById")
    @ApiOperation("根据作业id查看学生作业内容")
    public Page<HomeworkAnswer> queryHomeworkAnswerById(@RequestParam(value = "homeworkId")Integer homeworkId) {
        return teacherHomeworkService.queryHomeworkAnswerById(homeworkId);
    }

    @GetMapping("/queryHomeworkDetailById")
    @ApiOperation("根据id查询作业（任务）详细信息")
    public Page queryHomeworkDetailById(@RequestParam(value = "id")Integer id) {
        return teacherHomeworkService.queryHomeworkDetailById(id);
    }

    @GetMapping("/queryHomeworkSetById")
    @ApiOperation("根据id查询作业（设置）详细信息")
    public Page queryHomeworkSetById(@RequestParam(value = "homeworkId")Integer homeworkId) {
        return teacherHomeworkService.queryHomeworkSetById(homeworkId);
    }
}
